Skip to content

frames: record where each frame's device time went (CONTINUUM-ENGINE 4.13 step 1) - #142

Draft
joelteply wants to merge 6 commits into
fable/mind-switch-s4from
fable/frame-costs
Draft

joelteply wants to merge 6 commits into
fable/mind-switch-s4from
fable/frame-costs

Conversation

@joelteply

Copy link
Copy Markdown

Measure before changing anything (CONTINUUM-ENGINE 4.13, continuum ggml-org#6092). A fixed 4096-frame ring of per-frame decode/prefill step time, learning time, generation/prompt tokens, sequences and longest context; one summary line every 10 s (decode/prefill/learn/idle share of wall time, aggregate gen tok/s, widest batch, longest context). Separates the two M5 throughput causes of 2026-11-17 with data; the same records become the frame loop's cost curves and ServingObserver's numbers.

Model-free test: test-server-frame-costs (attribution by kind, idle, window bounds, ring keeps the newest N).

Not built locally (the M5 is serving; rule 2): CI is the compile proof.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…NUUM-ENGINE 4.13 step 1, measure before changing anything)

A fixed 4096-frame ring (server-frame-costs.h, no allocation per frame) of decode/prefill step time, learning time
after it, generation and prompt tokens, sequences and longest context; every 10 s one line: decode/prefill/learn/idle
shares of wall time, aggregate gen tok/s over wall and while stepping, widest batch, longest context. Separates the
two throughput causes seen on the M5 on 2026-11-17 (one mind seated; one stream at 24% of par) with data, and is the
record the frame loop's cost curves and the core's ServingObserver will read. Model-free test: test-server-frame-costs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply and others added 2 commits November 16, 2026 18:40
…ported by /metrics) with the recorder's own cost; the ring stays in the context (server_metrics is copied into every result); ring overwrites before a summary are counted and warned (Codex on ggml-org#6092: reuse the counter owner, measure overhead, report drops)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Author

Review exact 2513304: changes required before these records can drive cost curves or substantiate throughput.

  1. record_frame uses n_batch_gen as gen_tokens, but it is the generation-side batch size including draft/verification inputs, not accepted output tokens. It also counts the requested batch after decode/post_decode exceptions, and samples slot.is_processing after post_decode can finish/release slots. This can report work not completed and omit the very sequences that completed. Snapshot attempted batch geometry before mutation; record completed/accepted generation tokens and executed prompt tokens from their existing completion owners, separately from draft proposals/retries/errors. Prove speculative rejection, terminal-slot removal and a mid-batch failure with real caller coverage.
  2. t_step includes host decode/post_decode work and excludes pre_decode, rendering, adapter setup and other loop work. It is not GPU busy time; wall minus these segments is not GPU idle time. Keep explicit host elapsed, device-completed busy time (existing backend timestamp owner), and unclassified time. Mixed prefill/decode batches must not pretend their whole duration is an isolated prefill cost. Also decode_tps returns zero for an all-prefill/mixed window despite gen_tokens and a positive denominator; its stated semantics and formula disagree.
  3. frames_reported_us starts at0 while ggml_time_us is a monotonic epoch: the first report can include host uptime as idle, not the measurement interval. Initialize the measurement interval at recorder activation, define treatment of a frame crossing the boundary, and mark incomplete windows after ring overwrite; do not publish missing work as idle. Test nonzero clock origin and an overrun, not just fabricated records beginning near0.

Using server_metrics for cumulative exported counters and keeping the ring out of its copied response is sensible. But this needs a typed recorder read/drain contract and exact accounting first; logging a10-second summary is export, not a replayable captured hour. No merge/live-performance claim yet. #139 remains a separate stack dependency, including the corrected erase assertion; do not bring that entire branch live solely to obtain counters without its own review gates.

…block on 2513304)

- Work is what COMPLETED, from the owners that complete it: accepted output from n_tokens_generated (after
  speculative verification), prompt tokens from metrics_post_decode for decodes that succeeded, drafts proposed and
  accepted apart; outcome ok/retried/failed per frame.
- The batch's shape (sequences, longest context) is snapshotted from the batch BEFORE decode, so a slot released by
  its own completion is counted.
- Times are host elapsed, named as such: loop, batch (decode+post-decode), learning, unclassified rest; the time
  between iterations is 'outside the loop', never GPU idle. Mixed prefill+decode frames stay mixed.
- The recorder is created at serving start (metrics.t_start), so no window reaches into host uptime; a frame belongs
  to the window it ends in; a window the ring overwrote is marked INCOMPLETE.
- Typed read: every record has a sequence number; drain(after) returns them oldest first with an exact dropped count.
  The 10 s log line is an export only.
- Tests: model-free (nonzero clock origin, overrun, mixed/failed/retried, drain); real callers: accepted-per-frame
  equals tokens_predicted_total across n_predict 1/4/16 (terminal slots), and with a draft model whose drafts are
  partly rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Author

Re-review exact d146aa7. Accepted-output attribution, before-decode shape, host-time naming, activation origin and typed drain materially address the prior findings. I checked iterate(): on this base it is serial, so I am not reporting a shared-counter race.

Remaining issues before acceptance:

  • The pre_decode exception path returns before record_frame(), so this failed iteration and the work already spent in it vanish. Slot-local exceptions swallowed by iterate() also release a slot without marking frame outcome failed. Cover actual caller exits, including partial completion and exceptions, through one frame finalization owner; synthetic frame_outcome tests cannot demonstrate this. The acknowledged real-caller failure coverage is still required.
  • frame_shape_before_decode allocates a vector per iteration and scans the entire token batch. That contradicts the claimed no-allocation-per-frame instrumentation, and its cost is outside t_frame_record_us. Reuse bounded scratch storage or the batch's existing sequence ownership/geometry, and charge all instrumentation work (shape collection plus recording/export) to the reported overhead. Supply on/off overhead and identical-output evidence under realistic batches.

The device timestamp implementation I meant is your open #133 at8c0e1e42c62cbc0f98f10563457904f367dee0dd: ggml_metal_device_gpu_time_record/read in ggml-metal-device.{h,m}, command-buffer GPUStartTime/GPUEndTime callbacks in ggml-metal-context.m, exposed through ggml_backend_gpu_time in ggml-metal.cpp. It is not on this base yet. Host-only records are legitimate if labelled and scoped as host-only; do not infer device utilization from them or introduce a second timestamp collector.

This remains source review, not a merge or deployment approval. #139 dependency and exact CI gates remain separate.

joelteply and others added 2 commits November 16, 2026 18:57
…ed, no per-frame allocation (Codex on d146aa7)

- An RAII frame guard, created once the iteration has work, records the frame on normal end, on a failed pre_decode
  that returns early, and after decode failures; pre_decode failure marks the frame failed.
- Exceptions iterate() swallows (the slot is released with an error) are counted on the frame as slot_failures.
- The shape snapshot stamps a per-slot vector sized once at serving start: no per-frame allocation or clearing; its
  time is the frame's instrument_us, and the record's own write is added to the exported recording total; the log
  line reports recording cost as a share of loop time.
- Device time stays out: host-only and named so. The GPU timestamp owner (ggml_metal_device_gpu_time_record/read,
  ggml_backend_gpu_time) is on fork #133, not this base; device busy time joins when #133 lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… against), and proven through a real slot failure (Codex on 799a4c5)

- --frame-costs / LLAMA_ARG_FRAME_COSTS, a startup fact: without it no ring is created, no shape snapshot runs and
  no frame is recorded; test_frames_are_off_unless_asked pins that.
- frame_slot_failures_total on /metrics. test_failed_fill reuses the existing LLAMA_SERVER_TEST_FAULTS fill fault
  (no new fault switch): one slot's prompt fill throws inside iterate(), and the recorder counts exactly one slot
  failure, no failed frame, and accepted output equal to the surviving slot's predicted_n.
- the server tests pass --frame-costs through ServerProcess.frame_costs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant